package com.smart.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.pojo.ResultBean;
import com.smart.pojo.Salary;
import com.smart.req.SalaryReq;
import com.smart.resp.SalaryResp;
import com.smart.service.ISalaryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lyj
 * @since 2023-05-17
 */
@RestController
@RequestMapping("/salary")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @GetMapping("queryByCondition")
    public ResultBean queryByCondition(SalaryReq salaryReq) {
        System.out.println("查询薪资记录的条件：" + salaryReq);
        Page<SalaryResp> page = new Page<>(salaryReq.getPageNum(), salaryReq.getPageSize());

        salaryService.queryByCondition(salaryReq, page);
        return ResultBean.success(page);
    }

    @PostMapping("saveOrUpdate")
    @RequiresPermissions({"salary:save"})
    public ResultBean saveOrUpdate(@RequestBody Salary salary) {
        System.out.println("新增或修改的薪资数据：" + salary);
        boolean rs = salaryService.saveOrUpdate(salary);
        return rs ? ResultBean.success() : ResultBean.error();
    }

    @DeleteMapping("deleteById/{id}")
    @RequiresPermissions({"salary:del"})
    public ResultBean deleteById(@PathVariable("id") Long id) {
        System.out.println("要删除的薪资id：" + id);
        boolean rs = salaryService.removeById(id);
        return rs ? ResultBean.success() : ResultBean.error();
    }
}
